package cn.zwx.security.example.service.impl;

import cn.zwx.security.example.entity.SysMenuEntity;
import cn.zwx.security.example.entity.SysRoleEntity;
import cn.zwx.security.example.entity.SysUserEntity;
import cn.zwx.security.example.mapper.SysUserMapper;
import cn.zwx.security.example.service.SysUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description:
 * @projectName:spring-boot-security-example
 * @see:cn.zwx.security.example.service.impl
 * @author:zhangwenxue
 * @createTime:2021/6/23 16:47
 * @version:1.0
 */
@Service
public class SysUserServiceImpl implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    /**
     * @description 根据用户id查询角色
     * @return java.util.List<cn.zwx.security.example.entity.SysRoleEntity>
     * @author zhangwenxue
     * @createTime 2021/6/23 18:08
     **/
    @Override
    public List<SysRoleEntity> selectSysRoleByUserId(Long userId) {
        return this.sysUserMapper.selectSysRoleByUserId(userId);
    }


    /**
     * @description 查询用户菜单
     * @return java.util.List<cn.zwx.security.example.entity.SysMenuEntity>
     * @author zhangwenxue
     * @createTime 2021/6/23 18:26
     **/
    @Override
    public List<SysMenuEntity> selectSysMenuByUserId(Long userId) {
        return this.sysUserMapper.selectSysMenuByUserId(userId);
    }

    /**
     * @description 根据用户名称查询用户信息
     * @return cn.zwx.security.example.entity.extend.SelfUserEntity
     * @author zhangwenxue
     * @createTime 2021/6/23 16:49
     **/
    @Override
    public SysUserEntity loadUserByUsername(String userName) {
        QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SysUserEntity::getUsername,userName);
        return this.sysUserMapper.selectOne(queryWrapper);
    }

    @Override
    public List<SysUserEntity> list() {
        QueryWrapper<SysUserEntity> queryWrapper = new QueryWrapper<>();
        return this.sysUserMapper.selectList(queryWrapper);
    }
}
